package com.dgut.hisystem.mapper;

import com.dgut.hisystem.entity.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select({"SELECT yh_id, yh_email, yh_phone, yh_password, yh_idcard yh_idCard, yh_type, yh_name, yh_sex, yh_address FROM user_info WHERE yh_id=#{id}"})
    User getUserById(long id);

    void insert(User user);

    void update(User user);

    void delete(long id);

    @Select({"SELECT yh_id, yh_email, yh_phone, yh_password, yh_idcard yh_idCard, yh_type, yh_name, yh_sex, yh_address FROM user_info"})
    List<User> search();

    @Delete({"DELETE FROM user_info WHERE yh_phone = #{phone}"})
    void deleteByPhone(long phone);

    @Delete({"DELETE FROM user_info WHERE yh_idcard = #{idCard}"})
    void deleteByIdCard(String idCard);

    @Select({"SELECT yh_id, yh_email, yh_phone, yh_password, yh_idcard yh_idCard, yh_type, yh_name, yh_sex, yh_address FROM user_info WHERE yh_idcard = #{idCard}"})
    User getUserByIdCard(String idCard);

    @Select({"SELECT yh_id, yh_email, yh_phone, yh_password, yh_idcard yh_idCard, yh_type, yh_name, yh_sex, yh_address FROM user_info WHERE yh_phone = #{phone}"})
    User getUserByPhone(long phone);
}
